package gui.application;

import com.google.common.hash.Hashing;
import com.google.gson.Gson;
import gui.domain.License;
import gui.util.Base64Utils;
import java.nio.charset.StandardCharsets;
public class ComputerIdentifier {

  public static String getLicense(String machine) throws Exception {

//    String machine = "610503657d99e2b180ab630598d7b212a2ee01951886ea917f32f4980078f436";

    String hash = Hashing.sha256()
        .hashString(machine, StandardCharsets.UTF_8)
        .toString();

    License license = new License();
    license.setHash(hash);
    license.setCreateTime(System.currentTimeMillis());
    license.setExpireTime(System.currentTimeMillis() + (365 * 5 * 24 * 60 * 60 * 1000L));
    Gson gson = new Gson();
    String licenseJson = gson.toJson(license);
    return Base64Utils.encode(licenseJson.getBytes());
  }
}
